<template>
  <!--  <page-header-wrapper>-->
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="6" :sm="24">
            <a-form-item label="设备型号">
              <a-input v-model="queryParam.id" placeholder="请输入设备型号"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="设备名称">
              <a-input v-model="queryParam.id" placeholder="请输入设备名称"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="规格">
              <a-input v-model="queryParam.id" placeholder="请输入规格"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="24">
              <a-form-item label="生产厂商">
                <a-input v-model="queryParam.id" placeholder="请输入生产厂商"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="入库人员">
                <a-input v-model="queryParam.callNo" placeholder="请输入入库人员"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="更新日期">
                <a-date-picker v-model="queryParam.date" style="width: 100%" placeholder="请输入更新日期"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="!advanced && 6 || 8" :sm="24">
            <span class="table-page-search-submitButtons" :style="advanced && { float: 'left', overflow: 'hidden' } || {} ">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" @click="() => this.queryParam = {}">重置</a-button>
              <a @click="toggleAdvanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="handleAdd">添加入库</a-button>
      <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1"><a-icon type="delete" />删除</a-menu-item>
          <!-- lock | unlock -->
          <a-menu-item key="2"><a-icon type="lock" />锁定</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作 <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <s-table
      ref="table"
      bordered
      size="default"
      rowKey="key"
      :columns="columns"
      :data="loadData"
      :alert="true"
      :rowSelection="rowSelection"
      showPagination="auto"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
      <span slot="status" slot-scope="text">
        <a-badge :status="text | statusTypeFilter" :text="text | statusFilter" />
      </span>
      <span slot="description" slot-scope="text">
        <ellipsis :length="4" tooltip>{{ text }}</ellipsis>
      </span>
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="handle_equip(record)">出售设备</a>
        </template>
      </span>
    </s-table>
    <!--    // 添加入库modal-->
    <a-modal v-model="visible" :width="700" title="入库" @ok="handleOk">
      <a-radio-group v-model="indexStyle" style="margin-left: 20px;">
        <a-radio :value="1">入库</a-radio>
        <a-radio :value="2">已有入库</a-radio>
      </a-radio-group>
      <div v-if="indexStyle==1">
        <a-form layout="inline" :form="form">
          <a-row style="width: 100%;padding-top: 20px;">
            <a-col :span="24 / 2">
              <a-form-item label="试妆参数" hasFeedback>
                <a-select style="width: 195px" v-decorator="['type', {}]" placeholder="请选择服务号类型">
                  <a-select-option value="0">没有微信服务号</a-select-option>
                  <a-select-option value="1">JM跨境购</a-select-option>
                  <a-select-option value="2">唯品会合肥城市奥莱服务号</a-select-option>
                  <a-select-option value="3">挑剔小姐MISS PICKY</a-select-option>
                  <a-select-option value="4">美丽旅程</a-select-option>
                  <a-select-option value="5">海蜇优品</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="24 / 2">
              <a-form-item label="设备规格" hasFeedback>
                <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row style="width: 100%;padding-top: 20px;">
            <a-col :span="24 / 2">
              <a-form-item label="设备型号" hasFeedback>
                <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
              </a-form-item>
            </a-col>
            <a-col :span="24 / 2">
              <a-form-item label="生产厂商" hasFeedback>
                <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row style="width: 100%;padding-top: 20px;">
            <a-col :span="24 / 2">
              <a-form-item label="设备名称" hasFeedback>
                <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
              </a-form-item>
            </a-col>
            <a-col :span="24 / 2">
              <a-form-item label="入库人员" hasFeedback>
                <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row style="width: 100%;padding-top: 20px;">
            <a-col :span="24 / 2">
              <a-form-item label="入库数量" hasFeedback>
                <a-input style="width: 195px" placeholder="请输入联系人电话" v-decorator="['gateway', {}]" />
              </a-form-item>
            </a-col>
            <a-col :span="24 / 2">
              <a-form-item label="入库日期" hasFeedback>
                <a-date-picker show-time placeholder="选择时间" @change="onChange" @ok="onOk" >

                </a-date-picker>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div v-if="indexStyle==2">
        <a-form layout="inline" :form="form">
          <a-row :gutter="24"style="width: 100%;padding-top: 20px;">
            <a-col :span="12">
              <a-form-item label="设备名称" hasFeedback>
                <a-select style="width: 195px" v-decorator="['type', {}]" placeholder="请选择">
                  <a-select-option value="0">美妆镜1</a-select-option>
                  <a-select-option value="1">美妆镜2</a-select-option>
                  <a-select-option value="2">美妆镜3</a-select-option>
                  <a-select-option value="3">美妆镜4</a-select-option>
                  <a-select-option value="4">美妆镜5</a-select-option>
                  <a-select-option value="5">美妆镜6</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row style="width: 100%;padding-top: 20px;">
            <a-col :span="12">
              <a-form-item label="入库人员" hasFeedback>
                <a-input style="width: 195px" placeholder="请输入入库人员" v-decorator="['gateway', {}]" />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row style="width: 100%;padding-top: 20px;">
            <a-col :span="12">
              <a-form-item label="入库数量" hasFeedback>
                <a-input style="width: 195px" placeholder="请输入入库数量" v-decorator="['gateway', {}]" />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="24"style="width: 100%;padding-top: 20px;">
            <a-col :span="12">
              <a-form-item label="入库日期" hasFeedback>
                <a-date-picker show-time placeholder="选择时间" @change="onChange" @ok="onOk" />
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-modal>
    <!--  出售设备 modal  -->
    <a-modal v-model="visible2" :width="600" title="出售设备" @ok="handleOk2">
      <a-form layout="inline" :form="form" :label-col="{span:10}" :wrapper-col="{ span: 14 }" @submit="handleSubmit">
        <a-row style="width: 100%;">
          <a-col :span="15">
            <a-form-item label="设备名称" hasFeedback>
              <a-input style="width: 195px" placeholder="请输入设备名称" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item label="出货人员" hasFeedback>
              <a-input style="width: 195px" placeholder="请输入设备名称" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24"style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item label="肤质检测型号" hasFeedback>
              <a-select style="width: 185px" v-decorator="['type', {}]" placeholder="请选择">
                <a-select-option value="0">美妆镜1</a-select-option>
                <a-select-option value="1">美妆镜2</a-select-option>
                <a-select-option value="2">美妆镜3</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item label="商家名称" hasFeedback>
              <a-select style="width: 195px" v-decorator="['type', {}]" placeholder="请选择">
                <a-select-option value="0">美妆镜1</a-select-option>
                <a-select-option value="1">美妆镜2</a-select-option>
                <a-select-option value="2">美妆镜3</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row style="width: 100%;padding-top: 20px;margin-left: 30px;">
          <a-col :span="15">
            <a-form-item style="width: 195px" label="出货数量" hasFeedback>
              <a-input-number
                id="inputNumber"
                v-model="number_chushou"
                :min="1"
                :max="4"
                @change="onChange_chushou" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item label="账号编码1" hasFeedback>
              <a-input style="width: 190px" placeholder="请输入入库数量" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row v-if="number_chushou >=2 " style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item label="账号编码2" hasFeedback>
              <a-input style="width: 190px" placeholder="请输入入库数量" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row v-if="number_chushou >=3 " style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item label="账号编码3" hasFeedback>
              <a-input style="width: 190px" placeholder="请输入入库数量" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row v-if="number_chushou >=4 " style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item label="账号编码4" hasFeedback>
              <a-input style="width: 190px" placeholder="请输入入库数量" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24"style="width: 100%;padding-top: 20px;">
          <a-col :span="15">
            <a-form-item label="出售时间" hasFeedback>
              <a-date-picker show-time placeholder="选择时间" @change="onChange_chushou" @ok="onOk" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-modal>
  </a-card>
<!--  </page-header-wrapper>-->
</template>

<script>
import moment from 'moment'
import { STable, Ellipsis } from '@/components'
import { getRoleList, getServiceList } from '@/api/manage'

const columns = [
  {
    title: '#',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '设备型号',
    align: 'center',
    dataIndex: 'no'
  },
  {
    title: '设备名称',
    align: 'center',
    dataIndex: 'description',
    scopedSlots: { customRender: 'description' }
  },
  {
    title: '规格',
    align: 'center',
    dataIndex: 'callNo',
    sorter: true,
    needTotal: true,
    customRender: (text) => text + ' 次'
  },
  {
    title: '生产厂商',
    align: 'center',
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '入库人员',
    align: 'center',
    dataIndex: 'description',
    scopedSlots: { customRender: 'description' }
  },
  {
    title: '库存数量',
    align: 'center',
    dataIndex: 'callNo',
    sorter: true,
    needTotal: true,
    customRender: (text) => text + ' 次'
  },
  {
    title: '入库数量',
    align: 'center',
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '入库时间',
    align: 'center',
    dataIndex: 'updatedAt',
    sorter: true
  },
  {
    title: '操作',
    align: 'center',
    dataIndex: 'action',
    width: '150px',
    scopedSlots: { customRender: 'action' }
  }
]

const statusMap = {
  0: {
    status: 'default',
    text: '关闭'
  },
  1: {
    status: 'processing',
    text: '运行中'
  },
  2: {
    status: 'success',
    text: '已上线'
  },
  3: {
    status: 'error',
    text: '异常'
  }
}

export default {
  name: 'EquipmentModelA',
  components: {
    STable,
    Ellipsis
  },
  data () {
    this.columns = columns
    return {
      // create model
      visible: false,
      visible2: false,
      confirmLoading: false,
      indexStyle: 1,
      number_chushou: 1,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        console.log('loadData request parameters:', requestParameters)
        return getServiceList(requestParameters)
          .then(res => {
            return res.result
          })
      },
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  filters: {
    statusFilter (type) {
      return statusMap[type].text
    },
    statusTypeFilter (type) {
      return statusMap[type].status
    }
  },
  created () {
    getRoleList({ t: new Date() })
  },
  computed: {
    rowSelection () {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      }
    }
  },
  methods: {
    handleAdd () {
      this.mdl = null
      this.visible = true
    },
    handleEdit (record) {
      this.visible = true
      this.mdl = { ...record }
    },
    handleOk () {
      if (this.indexStyle == 1) {
        alert('入库点击确认')
      } else if (this.indexStyle == 2) {
        alert('已有入库点击确认')
      }
      this.visible = false
    },
    // 出售设备
    handle_equip () {
      this.visible2 = true
    },
    handleOk2 (e) {
      alert('出售设备点击确认')
      console.log(e)
      this.visible2 = false
    },
    handleCancel () {
      this.visible = false

      const form = this.$refs.createModal.form
      form.resetFields() // 清理表单数据（可不做）
    },
    handleSub (record) {
      if (record.status !== 0) {
        this.$message.info(`${record.no} 订阅成功`)
      } else {
        this.$message.error(`${record.no} 订阅失败，规则已关闭`)
      }
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    resetSearchForm () {
      this.queryParam = {
        date: moment(new Date())
      }
    }
  }
}
</script>
